package company.managedbean;

import company.entity.Company;
import java.io.Serializable;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import company.session.stateless.CompanySessionBean;
import java.io.IOException;

@ManagedBean(name = "createNewCompanyManagedBean")
@ViewScoped
public class CreateNewCompanyManagedBean implements Serializable {

    @EJB
    CompanySessionBean companySessionBean;
    private Company company;
       
    public CreateNewCompanyManagedBean() {
        company = new Company();
        company.setCompanyStatus("Sales Lead");

    }

    public void saveNewCompany(ActionEvent event) throws IOException {

        companySessionBean.saveNewCompany(company);
        
        //System.out.println(event.getComponent().getAttributes().get("param1"));
        
        FacesContext.getCurrentInstance().getExternalContext().getFlash().put("newCompany", company);
        FacesContext.getCurrentInstance().getExternalContext().redirect("createNewResult.xhtml");
    }

    public Company getCompany() {
        return company;
    }

    public void setCompany(Company company) {
        this.company = company;
    }
}
